<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>数据导出</title>
<link href="<?php echo ROOT_DIR?>libraries/theme/body.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?php echo ROOT_DIR?>libraries/theme/JQuery.js"></script>
<script type="text/javascript" src="<?php echo ROOT_DIR?>libraries/theme/RaysnWeb.js"></script>
<script type="text/javascript" src="<?php echo ROOT_DIR?>libraries/theme/ajaxpost.js"></script>
<script type="text/javascript">
var Exporting = 0;
var TableList = [];

$(function(){
	$(':button[name="confirm"]').click(function(){
		$(':checkbox:checked').each(function(i){
			TableList[i] = this.value;
		});

		if ( TableList[ Exporting ] == 'undefined' ){
			return false;
		}
		if ( ! $('#raysn_clewbox').is('div') ){
			$('form').before( '<div id="raysn_clewbox"></div>' );
		}

		$(':input').attr('disabled', true);
		RaysnWeb.ExportData( TableList );
		return false;
	});
});

RaysnWeb.ExportData = function( TableList ){
	$.ajax({
		type: "post",
		url: window.location.href,
		data: 'table='+TableList[ Exporting++ ]+'&Classify='+$(':hidden[name="Classify"]').val()+'&ajax=&confirm=ok',
		dataType: 'json',
		success: function( Result )
		{
			$("#raysn_clewbox").replaceWith( Result.Message );
			RaysnWeb.ScrollIntoView(document.getElementById('form1').parentNode);
			if ( Exporting < TableList.length ) {
				RaysnWeb.ExportData(TableList);
			} else {
				setTimeout("window.location= '<?php echo url('data/backup/'.$Classify)?>'", 1600);
			}
		},
		error: function( ) { }
	});
}
</script>
</head>
<body>
<h2>
	<a href="<?php echo url( 'data/list' )?>">返回数据列表</a>
	<span>数据导出</span>
</h2>

<?php echo show_messages();?>
<form id="form1" action="" method="post">
<input type="hidden" name="Classify" value="<?php echo $Classify?>" />
<div class="fieldset">
<div class="legend"><span>数据导出</span></div>
<ul>
	<li>
		<h3>导出列表：<em>*</em></h3>
		<?php foreach( $TableList as $tablename ){
		echo '<h5 class="leaf"><input type="checkbox" name="tables[]" value="'. $tablename .'" checked />'
		. '<strong><em>' . $TableTitles[$tablename] . '</em></strong>： [ 表名：' . $tablename . ' ] '
		. '</h5>';
		}?>
	</li>
	<li>
		<h3>导出格式：</h3>
		<h5 class="arrow">CSV逗号分隔值文件</h5>
	</li>
</ul>
</div>

<p>
	<input type="button" name="confirm" value="确认提交" />
	<input type="reset" value="重置" />
	<input type="button" onClick="javascript:history.go(-1);" value="返回" />
</p>
</form>
</body>
</html>
